package com.zuipin.controller;

import java.math.BigDecimal;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.zuipin.entity.NewsInfoImg;
import com.zuipin.framework.annotation.Inject;
import com.zuipin.framework.annotation.Valid;
import com.zuipin.framework.annotation.Valids;
import com.zuipin.framework.emuns.ErrorCode;
import com.zuipin.framework.result.PageResult;
import com.zuipin.framework.result.Result;
import com.zuipin.service.INewsInfoImgService;
import com.zuipin.util.Pagination;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 新闻相册Controller
 * 
 * @ClassName: NewsInfoImgController
 * @Description: TODO
 * @author robot
 * @date 2017年09月147日 13:56:06
 */
@Api(value = "新闻相册", description = "新闻相册")
@RestController
@RequestMapping(value = "/newsInfoImg")
public class  NewsInfoImgController {
	@Resource
	public INewsInfoImgService newsInfoImgService;

	
	@RequestMapping(value = "/get", method = RequestMethod.GET)
	@ApiOperation(value = "根据主键查询新闻相册", notes = "查询新闻相册")
	public Result<NewsInfoImg> getNewsInfoImgById(@ApiParam(required = true, name = "id", value = "ID") @RequestParam Long id){
		NewsInfoImg newsInfoImg = newsInfoImgService.findById(id);
		Result<NewsInfoImg> result = new Result<NewsInfoImg>();
		if (newsInfoImg != null) {
			result.setData(newsInfoImg);
			result.setErrorCode(ErrorCode.SUCCESS);
		} else {
			result.setErrorCode(ErrorCode.ELSE);
		}
		return result;
	}
	
	@RequestMapping(value = "/insert", method = RequestMethod.POST)
	@ApiOperation(value = "新增新闻相册", notes = "新增新闻相册")
	@Valids({
		
		@Valid(name = "newsInfoImg.newsInfoId",  maxLength = 19),
		@Valid(name = "newsInfoImg.TYPE",  maxLength = 6),
		@Valid(name = "newsInfoImg.imgUrl",  maxLength = 255),
		@Valid(name = "newsInfoImg.delFlag",  maxLength = 3),
		@Valid(name = "newsInfoImg.createId",  maxLength = 19),
		@Valid(name = "newsInfoImg.createTime",  maxLength = 19),
		@Valid(name = "newsInfoImg.updateId",  maxLength = 19),
		@Valid(name = "newsInfoImg.updateTime",  maxLength = 19),
		@Valid(name = "newsInfoImg.imgKey",  maxLength = 255),
	})
	@ApiImplicitParams({
		
		@ApiImplicitParam(name = "newsInfoImg.newsInfoId", value = "新闻ID",  dataType = "newsInfoId", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.TYPE", value = "图片类型",  dataType = "tYPE", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.imgUrl", value = "图片地址",  dataType = "imgUrl", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.delFlag", value = "删除标志:1是删除，0是未删除", required = true, dataType = "delFlag", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.createId", value = "创建者",  dataType = "createId", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.createTime", value = "创建时间",  dataType = "createTime", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.updateId", value = "更新者",  dataType = "updateId", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.updateTime", value = "更新时间",  dataType = "updateTime", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.imgKey", value = "前端使用的key",  dataType = "imgKey", paramType = "query"),
	})
	public Result<NewsInfoImg> insertNewsInfoImg(@Inject @ApiIgnore NewsInfoImg newsInfoImg) {
		Result<NewsInfoImg> result = new Result<NewsInfoImg>();
		newsInfoImgService.insert(newsInfoImg);
		result.setData(newsInfoImg);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	@ApiOperation(value = "根据主键修改新闻相册", notes = "修改新闻相册")
	@Valids({ 
		@Valid(name = "newsInfoImg.id",  maxLength = 19),
		@Valid(name = "newsInfoImg.newsInfoId",  maxLength = 19),
		@Valid(name = "newsInfoImg.TYPE",  maxLength = 6),
		@Valid(name = "newsInfoImg.imgUrl",  maxLength = 255),
		@Valid(name = "newsInfoImg.delFlag",  maxLength = 3),
		@Valid(name = "newsInfoImg.createId",  maxLength = 19),
		@Valid(name = "newsInfoImg.createTime",  maxLength = 19),
		@Valid(name = "newsInfoImg.updateId",  maxLength = 19),
		@Valid(name = "newsInfoImg.updateTime",  maxLength = 19),
		@Valid(name = "newsInfoImg.imgKey",  maxLength = 255),
	})
	@ApiImplicitParams({
		@ApiImplicitParam(name = "newsInfoImg.id", value = "ID", required = true, dataType = "id", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.newsInfoId", value = "新闻ID", dataType = "newsInfoId", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.TYPE", value = "图片类型", dataType = "tYPE", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.imgUrl", value = "图片地址", dataType = "imgUrl", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.delFlag", value = "删除标志:1是删除，0是未删除", required = true, dataType = "delFlag", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.createId", value = "创建者", dataType = "createId", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.createTime", value = "创建时间", dataType = "createTime", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.updateId", value = "更新者", dataType = "updateId", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.updateTime", value = "更新时间", dataType = "updateTime", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.imgKey", value = "前端使用的key", dataType = "imgKey", paramType = "query"),
	})
	public Result<NewsInfoImg> updateNewsInfoImg(@Inject @ApiIgnore NewsInfoImg newsInfoImg) {
		Result<NewsInfoImg> result = new Result<NewsInfoImg>();
		newsInfoImgService.update(newsInfoImg);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/del", method = RequestMethod.DELETE)
	@ApiOperation(value = "根据主键删除新闻相册", notes = "删除新闻相册")
	public Result<NewsInfoImg> delNewsInfoImg( Long id) {
		Result<NewsInfoImg> result = new Result<NewsInfoImg>();
		newsInfoImgService.delete(id);
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
	@RequestMapping(value = "/seach", method = RequestMethod.POST)
	@ApiOperation(value = "搜索新闻相册SKU新闻相册并分页", notes = "搜索新闻相册并分页")
	@Valids({
		
		@Valid(name = "newsInfoImg.newsInfoId",  maxLength = 19),
		@Valid(name = "newsInfoImg.TYPE",  maxLength = 6),
		@Valid(name = "newsInfoImg.imgUrl",  maxLength = 255),
		@Valid(name = "newsInfoImg.delFlag",  maxLength = 3),
		@Valid(name = "newsInfoImg.createId",  maxLength = 19),
		@Valid(name = "newsInfoImg.createTime",  maxLength = 19),
		@Valid(name = "newsInfoImg.updateId",  maxLength = 19),
		@Valid(name = "newsInfoImg.updateTime",  maxLength = 19),
		@Valid(name = "newsInfoImg.imgKey",  maxLength = 255),
		@Valid(name = "page.pageNumber",  maxValue = 999),
		@Valid(name = "page.pageSize",  maxValue = 999),
	})
	@ApiImplicitParams({
		
		@ApiImplicitParam(name = "newsInfoImg.newsInfoId", value = "新闻ID", dataType = "newsInfoId", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.TYPE", value = "图片类型", dataType = "tYPE", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.imgUrl", value = "图片地址", dataType = "imgUrl", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.delFlag", value = "删除标志:1是删除，0是未删除", required = true, dataType = "delFlag", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.createId", value = "创建者", dataType = "createId", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.createTime", value = "创建时间", dataType = "createTime", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.updateId", value = "更新者", dataType = "updateId", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.updateTime", value = "更新时间", dataType = "updateTime", paramType = "query"),
		@ApiImplicitParam(name = "newsInfoImg.imgKey", value = "前端使用的key", dataType = "imgKey", paramType = "query"),
		@ApiImplicitParam(name = "page.pageNumber", value = "页码", required = true, dataType = "integer", paramType = "query"),
		@ApiImplicitParam(name = "page.pageSize", value = "单页记录数", required = true, dataType = "integer", paramType = "query"),
	})
	public Result<List<NewsInfoImg>> seachNewsInfoImg(@Inject @ApiIgnore NewsInfoImg newsInfoImg,
			@Inject @ApiIgnore Pagination page) {
		PageResult<List<NewsInfoImg>> result = new PageResult<List<NewsInfoImg>>();
		result.setData(newsInfoImgService.seachNewsInfoImg(newsInfoImg, page));
		result.setTotal_record(page.getTotalRecord());
		result.setErrorCode(ErrorCode.SUCCESS);
		return result;
	}
	
}
